//================
//basic 函数
//================
if(window.jQuery && !window.jQuery.PPF) {
(function($){
	var _extendToPPF = {
		extend : function( v ) {
			try{delete v.extend;}catch(e){}
			$.extend( _extendToPPF , v );
			/*for(var e in v) {
				if(e != 'extend')
					_extendToPPF[e] = v[e];
			}*/
		}
	};
	$.extend({
		PPF: _extendToPPF
	});
	//EXPOSE
	window.$PPF = window.PPF = window.$ppf = window.ppf = window.$.PPF;
	
	$.fn.extend({
		content : function(param) {
			s = this.html();
			s = s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
			s = $.trim(s);
			s = s.replace(/^<\!\[CDATA\[([\s\S]*)\]\]>$/im, '$1');
			s = s.replace(/^<\!--([\s\S]*)-->$/im, '$1');
			if(param){
				for(var e in param){
					s = s.replace(new RegExp("\\{#" + e + "\\}","g"),param[e]);
				}
			}
			s = s.replace(new RegExp("\\{#[A-Za-z0-9_]*\\}","g"),'');
			return s;
		},
		moveable : function(p) {
			var b;
			if(p){
				b = $(p,this);
			}else {
				b = $(this);
			}
			var _t = $(this);
			b.css({cursor: 'move'});
			_t.css({position: 'absolute'});
			b.mousedown(function(event){
				event = event || window.event;
				var offset = _t.offset();
				var ex = event.x?event.x:event.pageX;
				var ey = event.y?event.y:event.pageY;
				var x1=ex-offset.left;
	      var y1=ey-offset.top;
	    	//var x1=event.clientX-offset.left;
	      //var y1=event.clientY-offset.top;
	      if(b.get(0).setCapture)
	      	b.get(0).setCapture();
	      else if(window.captureEvents){
	      	window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
	      }
        $(document).mousemove(function(event){
        	event = event || window.event;
        	var mx = event.x?event.x:event.pageX;
        	var my = event.y?event.y:event.pageY;
	        var l = Math.min(Math.max($(window).scrollLeft(),mx-x1),$(document.body).width()+$(window).scrollLeft()-_t.width()-10);
	        var t = Math.min(Math.max($(window).scrollTop(),my-y1),$(window).height()+$(window).scrollTop()-_t.height()-10);
        	//var l = mx-x1;
	       //var t = my-y1;
        	_t.css({left: l ,	top:t});
        	doane(event)
        });
        document.onselectstart = function(){return false;};
        $(document).mouseup(function(event){
					if(b.get(0).releaseCapture){
						b.get(0).releaseCapture();
					}else if(window.releaseEvents){
						window.releaseEvents(Event.MOUSEMOVE|Event.MOUSEUP);
					}
					$(document).unbind("mousemove");
					document.onselectstart = null;
					$(document).unbind("mouseup");
        });
        doane(event);
			});
			function doane(event){
				e = event || window.event;
				if( $.browser.msie ){
					e.returnValue = false;
					e.cancelBubble = true;
				}else if(e) {
					try{e.stopProgagation();
					e.preventDefault();}catch(e){}
				}
			}
			return this;
		},
		ptree: function() {
			var _t = this;
			$("span.Closed,span.Opened",this).click(function(){
				if($(this).parent().hasClass("Opened")) {
					$(this).parent().removeClass("Opened").addClass("Closed");
				}else if($(this).parent().hasClass("Closed")){
					$(this).parent().removeClass("Closed").addClass("Opened");
				}
			});
			var _f=function(){
				if($(this).hasClass("Opened")) {
					$("li.Closed,li.Opened",_t).removeClass("Opened").addClass("Closed");
					$(this).removeClass("Opened").addClass("Closed");
				}
				else {
					$("li.Closed,li.Opened",_t).removeClass("Closed").addClass("Opened");
					$(this).removeClass("Closed").addClass("Opened");
				}
			}
			$(".toggle",this).toggle(_f,_f);
			return this;
		},
		ptreeselect: function() {
			$("input[type='checkbox']",this).click(function(){
				if( $(this).attr('checked') ) {
					//选择所有下级
					$( "input[type='checkbox']" , $(this).parent() ).attr('checked','checked');
					//所有同级选择的情况下选择上级
					var cd = nd = 0;
					cd = $(this).parent().parent().children("li").children("input[type='checkbox'][checked]").length;
					nd = $(this).parent().parent().children("li").children("input[type='checkbox']").length;
					if(cd == nd && nd > 0) {
						var fc = $("input[type='checkbox']:first",$(this).parent().parent().parent());
						if( fc && !fc.attr('checked') ) {
							fc.get(0).click();
							//fc.click();
						}
					}
				}else {
					//取消上级选择
					$(this).parents("li").each(function(){
						$("input[type='checkbox']:first",this).removeAttr('checked');
					});
					//取消下级选择
					$("input[type='checkbox']" , $(this).parent() ).removeAttr('checked');
				}
			})
		},
		radiotg: function(){
			$(this).each(function(){
				if($(this).attr('checked')){
					$(this).attr('ppfchecked',true);
				}
			});
			$(this).click(function(){
				if( $(this).attr('ppfchecked') ){
					$(this).removeAttr('checked');
					$(this).removeAttr('ppfchecked');
				}else{
					$("input[type='radio'][name='" + $(this).attr('name') + "']").removeAttr('ppfchecked');
					$(this).attr('ppfchecked', true);
					$(this).attr('checked','checked');
				}
			});
		}
	});
	$PPF.extend({
		version: '1.3.2',
		compObject: function (o,o2){
		    //对比对象
		    if(o == o2) {return true;}
		    if(typeof(o)=="undefined"||o==null||typeof(o)!="object"){return false;}
		    if(typeof(o2)=="undefined"||o2==null||typeof(o2)!="object"){return false;}
		    var l = 0;
		    var l2=0; 
		    for(var i in o) { 
		        l++; 
		    } 
		    for(var i in o2) { 
		        l2++; 
		    } 
		    if(l!=l2) {return false;}
		    if(o.constructor == o2.constructor){ 
		        for(var i in o){ 
		            if(typeof(o[i])=="object") {
		                if(!PPF.compObject(o[i],o2[i])) 
		                    return false; 
		            }else if(o[i]!=o2[i]) { 
		                return false;
		            }
		        } 
		        return true; 
		    }
		    return false; 
		},
		formatFen: function(f){
			var fen = parseFloat( f/__System.FENSIZE ).toString();
			if(fen.indexOf('.')){
				return fen.substr(0,fen.indexOf('.') + __System.FENSIZE.toString().length );
			}else{
				return fen;
			}
		},
		tips: function(cc,i) {
			var c;
			if(typeof cc === "string") {
				c = {msg: cc};
			}else{
				c = cc;
			}
			if(typeof i === "undefined") i=0;
			var msg = c.msg ? c.msg : 'attention'
			var timeout = c.timeout ? c.timeout : 0;
			var type = c.type ? c.type : 0;
			$("span[ppf='tips'][key='"+i+"']").remove();
			if(type == 1)
				var show = $('<span ppf="tips" class="ppf_tips_error"></span>');
			else
				var show = $('<span ppf="tips" class="ppf_tips"></span>');
			show.appendTo("body");
			show.html(msg);
			show.attr("key",i);
			var top = c['top'] ? c['top'] : ($(window).height()/4 + $(window).scrollTop());
			var left = c['left'] ? c['left'] : ($(window).width()/2 - $(show).width()/2 + $(window).scrollLeft());
			show.css({top:top,left:left});
			if(timeout) {
				setTimeout(function(){show.remove()},timeout);
			}
			this.tips.remove = function(i){
				if(typeof i === "undefined") i=0;
				$("span[ppf='tips'][key='"+i+"']").remove();
			}
		},
		param: function( data , key ) {
			var q = {};
			var _k = '';
			for(var k in data) {
				if(typeof key === "undefined") {
					_k = k;
				}else {
					_k = key + '[' + k +']';
				}
				if(typeof data[k] === "object") {
					var s = PPF.param(data[k],_k);
					for(var kk in s) {
						q[kk] = s[kk];
					}
				}else {
					q[_k] = data[k];
				}
			}
			return q;
		},
		content: function(exp,param) {
			return $(exp).content(param);
		},
		ptreeselect: function(e,tpl,g) {
			$(".selected",tpl).removeClass("selected");
			var s = '';
			var u = null;
			s = $(e).html();
			u = $( $(e,tpl).parent().parent().parent().children("a[key]") );
			while(u.size()) {
				s = u.html() + "&gt;&gt;" + s;
				u = $( $(u,tpl).parent().parent().parent().children("a[key]") );
			}
			$(g).html(s);
			$(e,tpl).parent().addClass("selected");
			return $(e).attr('key');
		},
		dialog: function(param) {	//title  msg/html callback 是否模式对话框
			if(typeof param === "undefined") param={};
			var msg = param.msg ? param.msg : "提示信息",
			iframe = param.iframe ? param.iframe : null,
			title = param.title ? param.title : "提示信息",
			type = typeof param.type==="undefined" ? 1 : param.type,
			mod = typeof param.mod === "undefined" ? true : param.mod,
			timeout = param.timeout ? param.timeout : 0 ,
			callback = typeof param.callback === "function" ? param.callback : function(){},
			nocancel = typeof param.nocancel ? param.nocancel : false,
			oncancel = typeof param.oncancel === "function" ? param.oncancel : function(){},
			button = param.button ? param.button : "确认",
			cancel = param.cancel ? param.cancel : "取消",
			focus = param.focus ? param.focus : 2,
			move = typeof param.move === "undefined" ? 1 : param.move;
			if(mod){
				PPF.lock(999,iframe?1:0);
			}
			var c = $("<div></div>").addClass("ppf_dialog").attr("id","ppf_dialog").css({ position:"absolute" , "z-index":1001})
					.append(
						$("<div></div>").addClass("d_main")
							.append('<div class="d_head"><h3></h3><button href="javascript:void(0)" title="关闭">&nbsp;</button></div>')
							.append('<div class="d_content"></div>')
							.append('<div class="d_footer"><button class="button_submit">' + button + '</button> <button class="button_cancel">' + cancel + '</button></div>')
						)
						c.appendTo("body");
						if(move)
							c.moveable(".d_head");
			if(param.width) {
				c.width(param.width);
				$(".d_content",c).css({"overflow-x": "auto"});
			}
			if(param.height) {
				$(".d_content",c).css({"height": param.height, "overflow-y": "auto"});
			}
			$(".d_head h3",c).html(title);
			if(iframe) {
				$(".d_content",c).append("<iframe width=\"" + (param.width-15) + "\" scrolling=\"auto\" height=\"" + (param.height ? param.height : 400) + "\" class=\"ppf_dialog_iframe\" frameborder=\"0\" src=\"about:blank\"/>");
				$("iframe",c).attr('src',iframe);
			}else {
				$(".d_content",c).append(msg);
			}
			c.css({top: ($(window).height()-c.height())/3 + $(window).scrollTop(),left: ($(window).width()-c.width())/2 + $(window).scrollLeft()});
			if(type == 0) $(".d_footer",c).remove();
			else if(type == 1) $(".button_cancel",c).remove();
			if(nocancel) $(".d_head button",c).remove();
			$(window).resize(function(){$("#ppf_dialog").css({top: ($(window).height()-c.height())/2 + $(window).scrollTop(),left: ($(window).width()-c.width())/2 + $(window).scrollLeft()});});
			$(".d_head button,.button_cancel",c).click(function(){oncancel();remove();});
			if(type == 2 ) {
				if(focus == 1)
					$(".button_cancel").get(0).focus();
				else if(focus == 2)
					$(".button_submit").get(0).focus();
			}
			else if(type == 1 && focus != 0) $(".button_submit").get(0).focus();
			$(".button_submit",c).click(function(){if( callback($("div.d_content",c))!="keep" ) remove()});
			if(timeout) setTimeout(function(){remove()},timeout);
			function remove() {
				c.remove();
				PPF.dialog.callback = null;
				PPF.dialog.oncancel = null;
				if(mod) $PPF.unlock();
			}
			function resize(param) {
				var p={};
				if(param.height) p.height = param.height;
				if(param.width) p.width = param.width;
				$(".d_content",c).css( p );
			}
			this.dialog.close = remove;
			this.dialog.resize = resize;
			this.dialog.callback = callback;
			this.dialog.oncancel = oncancel;
		},
		lock: function(z,ni) {
			if(!z) z = 999;
			if($("#ppf_cover_"+z).size()>0) return;
			var c = $("<div></div>").attr("id","ppf_cover_"+z);
			var h = Math.max($(document.body).height(),$(window).height());
			$(window).resize(function(){
				var h = Math.max($(document.body).height(),$(window).height());
				$("div[id^='ppf_cover_']").height( h ).css({position: "absolute"});
			});
			c.width( "100%" ).height( h ).css({
				position: "absolute",left: 0, top: 0, opacity:0.5, "z-index":z , background: "#D6D6D6"
			});
			if($.browser.msie && !ni){	//ie遮蔽iframe
				c.append('<iframe frameborder="0" src="about:blank" style="z-index:-1;width:100%;height:100%;top:0px;left:0px;position:absolute"></iframe>');
			}
			c.appendTo("body");
		},
		unlock: function(z) {
			if(!z) z = 999;
			$("#ppf_cover_"+z).remove();
		},
		jsonmsg: function(s,df) {
			if(typeof s === "object" && typeof s._code !== "undefined"){
				msg = s._msg ? s._msg : df;
				if( s._code == 0) {
					return msg;
				}else {
					return "错误:"+msg;
				}
			}else if(typeof s === "string"){
				return s;
			}else {
				return df;
			}
		},
		timeFormate:function(t){
			var s='';
			var d=3600*24,h=3600,m=60;
			t = parseInt(t);
			if(t >= d){
				s += Math.floor( t/d ) + "天";
				t = t % d;
			}
			if(t >= h){
				s += Math.floor( t/h ) + "小时";
				t = t % h;
			}
			if(t >=m){
				s += Math.floor( t/m ) + "分";
				t = t % m;
			}
			if(t > 0){
				s += t + "秒";
			}
			return s;
		},
		cookie: function(name, value, options) {
	    if (typeof value != 'undefined') { // name and value given, set cookie
	        options = options || {};
	        if (value === null) {
	            value = '';
	            options.expires = -365 * 24 * 3600;
	        }
	        var expires = '';
	        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
	            var date;
	            if (typeof options.expires == 'number') {
	                date = new Date();
	                date.setTime(date.getTime() + (options.expires * 1000));	//second!
	            } else {
	                date = options.expires;
	            }
	            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
	        }
	        /**
	        CAUTION: Needed to parenthesize options.path and options.domain
	        in the following expressions, otherwise they evaluate to undefined
	        in the packed version for some reason...
	        */
	        var path = options.path ? '; path=' + (options.path) : '';
	        if(typeof options.domain == "undefined") options.domain = $.trim(__System.cookiedomain);
	        var domain = options.domain ? '; domain=' + (options.domain) : '';
	        var secure = options.secure ? '; secure' : '';
	        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
	    }else{ // only name given, get cookie
	        var cookieValue = null;
	        if (document.cookie && document.cookie != '') {
	            var cookies = document.cookie.split(';');
	            for (var i = 0; i < cookies.length; i++) {
	                var cookie = $.trim(cookies[i]);
	                // Does this cookie string begin with the name we want?
	                if (cookie.substring(0, name.length + 1) == (name + '=')) {
	                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
	                    break;
	                }
	            }
	        }
	        return cookieValue;
	    }
		}
	});
	})(jQuery);
	//window.alert = function(msg){ PPF.dialog( {title:"提示信息",msg: msg,type:1, mod: true} ); }
}
//==================
//html 函数
//==================

if(window.jQuery && !window.jQuery.PPF.user){
	(function($){
		PPF.extend({
			user: {
				gdlen: 4
				,login:function(cb,nocancel,param){
					var _t = this;
					if(typeof param === "undefined") param={};
					var ti = param.title ? param.title : "请先登陆后再操作";
					PPF.dialog( {title:ti,content:"",msg:$("#login_tpl").content(),type:0,nocancel:nocancel} );
					$("#web_login_form").submit(
						function(){
							_t.logindo(function(){
									(function(){if(
										typeof cb === "function") cb();
										_t.updatestate();
										PPF.dialog.close();
									})();
								}
							)
							return false;
						}
					);
					$("#web_login input").get(0).focus();
					var gdk  = $("input[name='gdkey']",$("#web_login"));
					if(gdk.size() > 0) {
						var kdp = function(){
							var v = gdk.val();
							var reg = new RegExp("^[a-z0-9]{1," + _t.gdlen + "}$","i");
							if(! reg.test(v)){
								gdk.val(v.substr(0,v.length-1));
							}
						}
						gdk.keydown(kdp).keyup(kdp);
					}
				}
				,logindo:function(cb){
					var user = $("input[name='username']",$("#web_login"));
					var pass = $("input[name='password']",$("#web_login"));
					var gdk  = $("input[name='gdkey']",$("#web_login"));
					if(user.val().length < 1){PPF.tips( {msg: '请填用户名' , timeout:2000 , type: 1} );user.get(0).focus();return;}
					if(!pass.val()) {PPF.tips( {msg: '请填写密码' , timeout:2000 , type: 1} );pass.get(0).focus();return;}
					var u = user.val(),p=pass.val(),pk,rk;
					rk = gdk.size() > 0 && gdk.val() ? gdk.val() : Math.random();
					pk = PPF.md5( PPF.md5(p) + rk );
					var param = {inajax:1,username:u,passkey:pk,randkey:rk};
					if(gdk.size() > 0) {
						if(gdk.val().length != this.gdlen) { PPF.tips( {msg: '请填写验证码' , timeout:2000 , type: 1} );gdk.get(0).focus();return;}
						param.gdkey = gdk.val();
					}
					$.post( __System.roots.user + 'login' , param , function(data){
						if(data._code == 0){
							if(typeof cb == "function") cb();
						}else{
							gdreload($('#gdimg') , true);
							if(data._code == -121 ){ PPF.tips( {msg: PPF.jsonmsg(data,"登陆失败") , timeout:2000 , type: 1} ) ; gdk.val('').get(0).focus(); }
							else PPF.tips( {msg: PPF.jsonmsg(data,"用户名或者密码错误") , timeout:2000 , type: 1} );
						}
					},'json');
				}
				,logout:function(cb){
					$.post( __System.roots.user + 'logout' , {inajax:1} , function(data){
						if(data._code == 0) {
							if(typeof cb == "function") cb();
							else if(typeof callback_logout == "function") callback_logout();
							else PPF.user.updatestate();
						}else PPF.tips( {msg: PPF.jsonmsg(data,"退出失败") , timeout:2000 , type: 1} );
					},'json');
				}
				,updatestate:function(){
					if( this.islogin() ){
						$("#hlogin").html( "您好 " + this.username + "， 欢迎进入在线考试中心，<a href=\"" + __System.roots.user + "account.html\">个人中心</a> &nbsp; <a href=\"javascript:;\" onclick=\"PPF.user.logout()\">退出</a>" );
					}else{
						$("#hlogin").html( "您还没有登陆，<a href=\"javascript:;\" onclick=\"PPF.user.login()\">[请登录]</a> <a href=\"javascript:PPF.user.reg();\">[免费注册]</a>" );
					}
				}
				,islogin:function(){
					var c = PPF.cookie(__System.cookiepre + 'ppf_uname');
					if(!c){
						delete this.username;
						delete this.uid;
						return false;
					}
					var a = c.split("\t");
					if(a.length == 3 && a[2] > __System.time ) {
						this.username = a[0];
						this.uid = a[1];
						return true;
					}else{
						delete this.username;
						delete this.uid;
						return false;
					}
				}
				,reg: function(){
					if(!__System.regopen) {alert('系统关闭了注册');return;}
					reffer = (typeof __Sparams.reffer != "undefined" && __Sparams.reffer) ? __Sparams.reffer : location.href;
					location.href = __System.roots.user + 'reg?reffer=' + encodeURIComponent( reffer );
				}
			}
			,md5: function(str){
				var hexcase = 0;	//lowercase
				var b64pad = "";
				var chrsz = 8;
				
				function hex_md5(s){return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
				
				function core_md5(x, len)
				{
				  x[len >> 5] |= 0x80 << ((len) % 32);
				  x[(((len + 64) >>> 9) << 4) + 14] = len;
				
				  var a = 1732584193;
				  var b =  - 271733879;
				  var c =  - 1732584194;
				  var d = 271733878;
				
				  for (var i = 0; i < x.length; i += 16)
				  {
				    var olda = a;
				    var oldb = b;
				    var oldc = c;
				    var oldd = d;
				
				    a = md5_ff(a, b, c, d, x[i + 0], 7,  - 680876936);
				    d = md5_ff(d, a, b, c, x[i + 1], 12,  - 389564586);
				    c = md5_ff(c, d, a, b, x[i + 2], 17, 606105819);
				    b = md5_ff(b, c, d, a, x[i + 3], 22,  - 1044525330);
				    a = md5_ff(a, b, c, d, x[i + 4], 7,  - 176418897);
				    d = md5_ff(d, a, b, c, x[i + 5], 12, 1200080426);
				    c = md5_ff(c, d, a, b, x[i + 6], 17,  - 1473231341);
				    b = md5_ff(b, c, d, a, x[i + 7], 22,  - 45705983);
				    a = md5_ff(a, b, c, d, x[i + 8], 7, 1770035416);
				    d = md5_ff(d, a, b, c, x[i + 9], 12,  - 1958414417);
				    c = md5_ff(c, d, a, b, x[i + 10], 17,  - 42063);
				    b = md5_ff(b, c, d, a, x[i + 11], 22,  - 1990404162);
				    a = md5_ff(a, b, c, d, x[i + 12], 7, 1804603682);
				    d = md5_ff(d, a, b, c, x[i + 13], 12,  - 40341101);
				    c = md5_ff(c, d, a, b, x[i + 14], 17,  - 1502002290);
				    b = md5_ff(b, c, d, a, x[i + 15], 22, 1236535329);
				
				    a = md5_gg(a, b, c, d, x[i + 1], 5,  - 165796510);
				    d = md5_gg(d, a, b, c, x[i + 6], 9,  - 1069501632);
				    c = md5_gg(c, d, a, b, x[i + 11], 14, 643717713);
				    b = md5_gg(b, c, d, a, x[i + 0], 20,  - 373897302);
				    a = md5_gg(a, b, c, d, x[i + 5], 5,  - 701558691);
				    d = md5_gg(d, a, b, c, x[i + 10], 9, 38016083);
				    c = md5_gg(c, d, a, b, x[i + 15], 14,  - 660478335);
				    b = md5_gg(b, c, d, a, x[i + 4], 20,  - 405537848);
				    a = md5_gg(a, b, c, d, x[i + 9], 5, 568446438);
				    d = md5_gg(d, a, b, c, x[i + 14], 9,  - 1019803690);
				    c = md5_gg(c, d, a, b, x[i + 3], 14,  - 187363961);
				    b = md5_gg(b, c, d, a, x[i + 8], 20, 1163531501);
				    a = md5_gg(a, b, c, d, x[i + 13], 5,  - 1444681467);
				    d = md5_gg(d, a, b, c, x[i + 2], 9,  - 51403784);
				    c = md5_gg(c, d, a, b, x[i + 7], 14, 1735328473);
				    b = md5_gg(b, c, d, a, x[i + 12], 20,  - 1926607734);
				
				    a = md5_hh(a, b, c, d, x[i + 5], 4,  - 378558);
				    d = md5_hh(d, a, b, c, x[i + 8], 11,  - 2022574463);
				    c = md5_hh(c, d, a, b, x[i + 11], 16, 1839030562);
				    b = md5_hh(b, c, d, a, x[i + 14], 23,  - 35309556);
				    a = md5_hh(a, b, c, d, x[i + 1], 4,  - 1530992060);
				    d = md5_hh(d, a, b, c, x[i + 4], 11, 1272893353);
				    c = md5_hh(c, d, a, b, x[i + 7], 16,  - 155497632);
				    b = md5_hh(b, c, d, a, x[i + 10], 23,  - 1094730640);
				    a = md5_hh(a, b, c, d, x[i + 13], 4, 681279174);
				    d = md5_hh(d, a, b, c, x[i + 0], 11,  - 358537222);
				    c = md5_hh(c, d, a, b, x[i + 3], 16,  - 722521979);
				    b = md5_hh(b, c, d, a, x[i + 6], 23, 76029189);
				    a = md5_hh(a, b, c, d, x[i + 9], 4,  - 640364487);
				    d = md5_hh(d, a, b, c, x[i + 12], 11,  - 421815835);
				    c = md5_hh(c, d, a, b, x[i + 15], 16, 530742520);
				    b = md5_hh(b, c, d, a, x[i + 2], 23,  - 995338651);
				
				    a = md5_ii(a, b, c, d, x[i + 0], 6,  - 198630844);
				    d = md5_ii(d, a, b, c, x[i + 7], 10, 1126891415);
				    c = md5_ii(c, d, a, b, x[i + 14], 15,  - 1416354905);
				    b = md5_ii(b, c, d, a, x[i + 5], 21,  - 57434055);
				    a = md5_ii(a, b, c, d, x[i + 12], 6, 1700485571);
				    d = md5_ii(d, a, b, c, x[i + 3], 10,  - 1894986606);
				    c = md5_ii(c, d, a, b, x[i + 10], 15,  - 1051523);
				    b = md5_ii(b, c, d, a, x[i + 1], 21,  - 2054922799);
				    a = md5_ii(a, b, c, d, x[i + 8], 6, 1873313359);
				    d = md5_ii(d, a, b, c, x[i + 15], 10,  - 30611744);
				    c = md5_ii(c, d, a, b, x[i + 6], 15,  - 1560198380);
				    b = md5_ii(b, c, d, a, x[i + 13], 21, 1309151649);
				    a = md5_ii(a, b, c, d, x[i + 4], 6,  - 145523070);
				    d = md5_ii(d, a, b, c, x[i + 11], 10,  - 1120210379);
				    c = md5_ii(c, d, a, b, x[i + 2], 15, 718787259);
				    b = md5_ii(b, c, d, a, x[i + 9], 21,  - 343485551);
				
				    a = safe_add(a, olda);
				    b = safe_add(b, oldb);
				    c = safe_add(c, oldc);
				    d = safe_add(d, oldd);
				  }
				  return Array(a, b, c, d);
				}
				
				function md5_cmn(q, a, b, x, s, t)
				{
				  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s), b);
				}
				
				function md5_ff(a, b, c, d, x, s, t)
				{
				  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
				}
				
				function md5_gg(a, b, c, d, x, s, t)
				{
				  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
				}
				
				function md5_hh(a, b, c, d, x, s, t)
				{
				  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
				}
				
				function md5_ii(a, b, c, d, x, s, t)
				{
				  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
				}
				
				function core_hmac_md5(key, data)
				{
				  var bkey = str2binl(key);
				  if (bkey.length > 16)
				    bkey = core_md5(bkey, key.length * chrsz);
				
				  var ipad = Array(16), opad = Array(16);
				  for (var i = 0; i < 16; i++)
				  {
				    ipad[i] = bkey[i] ^ 0x36363636;
				    opad[i] = bkey[i] ^ 0x5C5C5C5C;
				  }
				
				  var hash = core_md5(ipad.concat(str2binl(data)), 512+data.length * chrsz);
				  return core_md5(opad.concat(hash), 512+128);
				}
				
				function safe_add(x, y)
				{
				  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
				  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
				  return (msw << 16) | (lsw & 0xFFFF);
				}
				
				function bit_rol(num, cnt)
				{
				  return (num << cnt) | (num  >>> (32-cnt));
				}
				
				function str2binl(str)
				{
				  var bin = Array();
				  var mask = (1 << chrsz) - 1;
				  for (var i = 0; i < str.length * chrsz; i += chrsz)
				    bin[i >> 5] |= (str.charCodeAt(i / chrsz) & mask) << (i % 32);
				  return bin;
				}
				
				function binl2str(bin)
				{
				  var str = "";
				  var mask = (1 << chrsz) - 1;
				  for (var i = 0; i < bin.length * 32; i += chrsz)
				    str += String.fromCharCode((bin[i >> 5] >>> (i % 32)) & mask);
				  return str;
				}
				
				function binl2hex(binarray)
				{
				  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
				  var str = "";
				
				  for (var i = 0; i < binarray.length * 4; i++)
				  {
				    str += hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8+4)) & 0xF) +
				      hex_tab.charAt((binarray[i >> 2] >> ((i % 4) * 8)) & 0xF);
				  }
				  return str;
				}
				return hex_md5(str);
			}
		});
	})(jQuery);
}

if(window.jQuery && !window.jQuery.PPF.html) {
	(function($){
	var html_treemenu = {
		parse: function(data) {
			if(typeof data !== 'object') return '';
			var $key = null,$val = null,$options = null,$selected = null,$content = null,$opened = 'all',$class = null,$id = null,$extra = '';
			for(var e in data) {
				switch(e) {
					case 'key':		//string
						$key = data[e];break;
	        case 'selected':	//string
	        	$selected = data[e];break;
	        case 'id':	//string
	        	$id = data[e];break;
	        case 'opened':	//string
	        	$opened = data[e];break;
	        case 'content':	//string
	        	$content = data[e];break;
	        case 'options':	//Array
	        	$options = data[e];break;
	        default:
	        	$extra += ' '+e+'="'+ data[e] +'"';break;
				}
			}
			if(!$key) $key='id'; if(!$val) $val='name'; 
	    if (!$options || !$content)
	        return '';
	    var _result = this.output($options,$selected,$key,$content,$opened,1);
	    
	    if ($id) {
	    	_result = '<div id="' + $id + '" ' + $extra + '>' + "\n" + _result + '</div>';
	    }
	    return _result;
		},
		output: function($options , $selected , $key , $content , $opened , $step ) {
			var $_rstr = '';
			$_rstr += '<ul>'+"\n";
			for(var i=0;i<$options.length;i++){
				var d = $options[i];
				var $_class = $step == 1 ? ($opened == 'open' || $opened == 'all' ? 'Opened' : 'Closed') : ( typeof d._s == 'object' ? ($opened == 'all' ? 'Opened' : 'Closed') : 'Child');
				var $_content = $content;
				for(var ee in d) {
					if(ee != '_s'){
						$_content = $_content.replace(new RegExp("{~" + ee + "~}","g"),d[ee]);
					}
				}
				if ($selected == d[$key]) {
					$_rstr += '<li class="' + $_class + ' selected"><span class="' + $_class + '"></span>' + $_content;
				}else {
					$_rstr += '<li class="' + $_class + '"><span class="' + $_class + '"></span>' + $_content;
				}
				if (typeof d._s == 'object') {
					$_rstr += this.output( d._s , $selected ,$key,$content,$opened,$step + 1);
				}
				$_rstr += '</li>'+"\n";
			}
			$_rstr += '</ul>'+"\n";
			return $_rstr;
		}
	};
	var html_checkboxes = {
		ids: {},
		parse: function(data) {
			var $name='checkbox',$options,$selected={},$separator='',$labels=true,$label_ids=false,$extra='',$noadd = false,$_key='',$_val='',$abc=false;
			for(var e in data) {
	        switch(e) {
	            case 'name':	//string
	            	$name=data[e];break;
	            case 'separator':	//string
	            	$separator=data[e];break;
	            case 'noadd':	//bool
	            	$noadd = data[e];break;
	            case 'labels':	//bool
								$labels = data[e];break;
	            case 'label_ids':	//bool
	            	$label_ids = data[e];break;
	            case 'options':	//object key => string
	            	$options = data[e];break;
	            case 'checked':
	            case 'selected':	//object key => bool
	            	if(typeof data[e] != "object")
	            		$selected[data[e]] = data[e];
	            	else
	              	$selected = data[e];
	              break;
	            case '_key':
								$_key = data[e];break;
							case '_val':
								$_val = data[e];break;
							case 'abc':
								$abc = data[e];break;
	            default :
	        			$extra += ' '+e+'="'+ data[e] +'"';break;
	        }
	    }
	    if (typeof $options!='object')
				return '';
	    var $_html_result = new Array();
			var i=0;
			var az = "ABCDEFGHIJGKMNOPQRSTUVWXYZ";
			for(var e in $options) {
				var output,value;
				if($_key && $_val){
					output = $options[e][$_val];
					value = $options[e][$_key];
				}else{
					value = e;
					output = $options[e];
				}
				if($abc)
					output = 	"<span class=\"pcur\">" + az.charAt(i) + "</span>"  + output;
					
				$_html_result[i] = this.output($name, value , output, $selected, $extra , $labels , $label_ids , $noadd);
				i++;
			}
	    return $_html_result.join($separator + "\n");
		},
		output: function($name, $value, $output, $selected, $extra, $labels , $label_ids , $noadd ) {
	    var $_output = '';
	    if ($labels) {
				if($label_ids) {
					var $_id = 'checkboxes_' + $name + '_' + $value;
					if( typeof this.ids[$_id] != "undefined" && this.ids[$_id] ){
						$_id += '_' + this.ids[$_id];
					}
					this.ids[$_id] = '1';
					$_output += '<label for="' + $_id + '">';
				} else {
					$_output += '<label>';
				}
			}
	    $_output += '<input type="checkbox" name="'
	        + $name + ($noadd ? '" value="' : '[]" value="')
	        + $value + '"';
	    if(typeof $selected[$value] != "undefined" && $selected[$value] && $selected[$value] != "false" && $selected[$value] != "0" && $selected[$value] != "null"){
	    	$_output += ' checked="checked"';
	    }
	    if ($labels && $label_ids) $_output += ' id="' + $_id + '"';
	    if($extra) $_output += $extra;
	    $_output += " />" + $output;
	    if ($labels) $_output += '</label>';
	    return $_output;
		}
	};
	var html_options = {
		parse: function(data) {
			var $name = '',$options = null,$selected = {},$attention='' ,$extra = '';
			for(var e in data){
				switch(e) {
					case 'name':
						$name = data[e];break;
					case 'attention':
					case 'guid':
						$attention = data[e];break;
					case 'options':
						$options = data[e];break;
					case 'selected':
					case 'checked':
						if(typeof data[e] != "object")
	          	$selected[data[e]] = data[e];
	         	else
	          	$selected = data[e];
	          break;
					default :
	        	$extra += ' '+e+'="'+ data[e] +'"';break;
				}
			}
			if (typeof $options!='object')
				return '';
			$_r = '';
			if($options){
				for(var e in $options){
					$_r += this.output(e,$options[e],$selected);
				}
			}
			if ($attention) {
				$_r = '<option value="" label="' + $attention + '">' + $attention + '</option>' . $_r;
			}
			if($name) {
				$_r = '<select name="' + $name + '"' + $extra + '>' + "\n" + $_r + '</select>' + "\n";
			}
			return $_r;
		},
		output: function( $key, $value, $selected ) {
			if(typeof $value != 'object') {
				$_html_result = '<option label="' + $value + '" value="' + $key + '"';
				if(typeof $selected[$key] != "undefined" && $selected[$key] && $selected[$key] != "false" && $selected[$key] != "0" && $selected[$key] != "null"){
					$_html_result += ' selected="selected"';
				}
				$_html_result += '>' + $value + '</option>' + "\n";
			}else {
				$_html_result = this.optgroup($key, $value, $selected);
			}
			return $_html_result;
		},
		optgroup: function($key, $values, $selected) {
			$optgroup_html = '<optgroup label="' + $key + '">' + "\n";
			for(var e in $value){
				$optgroup_html += this.output(e, $value[e], $selected);
			}
			$optgroup_html += "</optgroup>\n";
			return $optgroup_html;
		}
	};
	var html_radios = {
		parse:function(data){
			var $name = 'radio',$options = null,$selected = null,$separator = '',$labels = true,$label_ids = false,$output = null,$extra = '',$_key='',$_val='';
			for(var e in data){
				switch(e) {
					case 'name':
						$name = data[e];break;
					case 'separator':
						$separator = data[e];break;
					case 'checked':
					case 'selected':
						$selected = data[e];break;
					case 'labels':
						$labels = data[e];break;	//bool
					case 'label_ids':
						$label_ids = data[e];break;	//bool
					case 'options':
						$options = data[e];break;	//object key => val
					case '_key':
						$_key = data[e];break;
					case '_val':
						$_val = data[e];break;
					case 'abc':
						$abc = data[e];break;
					default:
						$extra += ' '+e+'="'+ data[e] +'"';break;
				}
			}
			if(typeof $options != "object")
				return '';
			var $_r = [];
			var i=0;
			var az = "ABCDEFGHIJGKMNOPQRSTUVWXYZ";
			if($options){
				for(var e in $options) {
					var output,value;
					if($_key && $_val){
						output = $options[e][$_val];
						value = $options[e][$_key];
					}else{
						value = e;
						output = $options[e];
					}
					if($abc)
						output = 	"<span class=\"pcur\">" + az.charAt(i) + "</span>"  + output;
					$_r[i] = this.output($name, value, output, $selected, $extra, $labels, $label_ids);
					i++;
				}
			}
			return $_r.join($separator + "\n");
		},
		output: function($name, $value, $output, $selected, $extra, $labels, $label_ids ) {
			var $_output = '';
			if ($labels) {
				if($label_ids) {
					var $_id = 'radios_' + $name + '_' + $value;
					$_output += '<label for="' + $_id + '">';
				} else {
					$_output += '<label>';
				}
			}
		  $_output += '<input type="radio" name="' + $name + '" value="' + $value + '"';
			if ($labels && $label_ids) $_output += ' id="' + $_id + '"';
			if ( $value == $selected ) {
				$_output += ' checked="checked"';
			}
			$_output += $extra + ' />' + $output;
			if ($labels) $_output += '</label>';
			return $_output;
		}
	};
	var html_treeoptions = {
		parse: function(data) {
			alert('developing');
		},
		output: function() {
			
		}
	};
	$PPF.extend({
			html: {
				treemenu: function(data) {
					return html_treemenu.parse(data);
				},
				checkboxes: function(data) {
					return html_checkboxes.parse(data);
				},
				options: function(data) {
					return html_options.parse(data);
				},
				radios: function(data) {
					return html_radios.parse(data);
				},
				treeoptions: function(data) {
					return html_treeoptions.parse(data);
				},
				json2checked: function(data){
					return data;
				}
			}
		});
	})(jQuery);
}

Date.prototype.toPPFstring = function(pattern) {
	var Y = this.getFullYear().toString(),m=(this.getMonth()+1).toString(),d=this.getDate().toString(),
	H=this.getHours().toString(),i=this.getMinutes().toString(),s=this.getSeconds().toString(),u=this.getMilliseconds().toString();
	return pattern
	.replace( /yyyy/g, Y )
	.replace( /MM/g, m.length<2 ? '0'+m : m )
	.replace( /dd/g, d.length<2 ? '0'+d : d )
	.replace( /hh/g, H.length<2 ? '0'+H : H )
	.replace( /ii/g, i.length<2 ? '0'+i : i )
	.replace( /ss/g, s.length<2 ? '0'+s : s )
	.replace( /uuu/g, u );
}
function updateSystemTime(){
	$("#systemtime").html( new Date( __System.time * 1000 ).toPPFstring('yyyy-MM-dd hh:ii:ss.uuu') );
	setTimeout( updateSystemTime , 100 );
}
jQuery(function($){
	//if($("#systemtime").size()>0) updateSystemTime();
});